<template>
    <div class="app-container">
        <!--<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
            <el-form-item label="标题" prop="title">
                <el-input v-model="queryParams.title" placeholder="请输入标题" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form> -->
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['business:notice:add']">新增</el-button>
            </el-col>

            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table @selection-change="handleSelectionChange" fit v-loading="loading" border :data="dataList">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="序号" type="index" />
            <!-- <el-table-column label="标题" prop="title" :show-overflow-tooltip="true">
            </el-table-column> -->
            <el-table-column label="类型" prop="userName" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    {{ scope.row.type == 1 ? '补报告说明及收费公示' : scope.row.type == 2 ? '临时报告说明及收费公示' : scope.row.type == 3 ?
                        '修改报告说明及收费公示' : scope.row.type == 4 ? "修改报告情况说明" : scope.row.type == 5 ? '检测报告信息更正申请书（轨道专用)' : "" }}
                </template>
            </el-table-column>
            <el-table-column align="center" label="发布时间" prop="createTime" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200" fixed="right">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-view" v-hasPermi="['business:notice:info']"
                        @click="handleDetail(scope.row)">详情</el-button>
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['business:notice:edit']">修改</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['business:notice:remove']">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />
        <!-- 添加或修改公司公告对话框 -->
        <el-dialog title="公告" :visible.sync="open" width="800px">
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <!-- <el-row>
                    <el-col :span="24">
                        <el-form-item label="标题" prop="title">
                            <el-input v-model="form.title" placeholder="请输入标题" />
                        </el-form-item>
                    </el-col>
                </el-row> -->
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="类型" prop="type">
                            <el-select v-model="form.type" placeholder="文件类型" clearable style="width: 240px">
                                <el-option label="补报告说明及收费公示" :value="1" />
                                <el-option label="临时报告说明及收费公示 " :value="2" />
                                <el-option label="修改报告说明及收费公示" :value="3" />
                                <el-option label="修改报告情况说明" :value="4" />
                                <el-option label="检测报告信息更正申请书（轨道专用)" :value="5" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="24">
                        <el-form-item label="文件内容">
                            <editor v-if="open" placeholder="请输入公告内容" v-model="form.content" :min-height="500" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <!-- <el-row>
                    <el-col :span="12">
                        <el-form-item label="是否显示" prop="status">
                            <el-switch v-model="form.status" active-value="1" inactive-value="0"></el-switch>
                        </el-form-item>
                    </el-col>
                </el-row> -->
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
        <detail :detailOPen.sync="detailOPen" :rowDetail="rowDetail" @cancel="cancel"></detail>
    </div>
</template>
  
<script>
import detail from '../textsFile/detail'
import {
    noticeList,
    advReportDel,
    advReportAdd,
    advReportEdit,
    advReportInfo,
} from "@/api/business/notice.js";
import { userSelect, deptTreeSelect } from "@/api/system/user.js";
export default {
    components: {
        detail,
    },
    name: "project",
    dicts: ["sys_comp_fee_status", "sys_fee_type"],

    data() {
        return {
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            dataList: [],
            // 遮罩层
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                ipAddress: this.$VUE_APP_IMG_API
            },
            rowDetail: {},
            form: {
                // status: 0,
                type: 1,
            },
            detailOPen: false,
            open: false,
            // 表单校验
            rules: {
                title: [
                    { required: true, message: "标题不能为空", trigger: "blur" },
                ],
                type: [
                    { required: true, message: "类型不能为空", trigger: "change" },
                ],
                content: [
                    { required: true, message: "内容不能为空", trigger: "blur" },
                ],
                // status: [
                //     { required: false, message: "类型不能为空", trigger: "change" },
                // ],
            },
            baseUrl: this.$VUE_APP_IMG_API,
        };
    },
    created() {
        this.getList();
        if(this.$VUE_APP_IMG_API == 'https://boss.jsstet-oa.com'){
            this.queryParams.ipAddress = 'https://yy.jsstet-oa.com'
        }
    },
    methods: {
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.advReportId);
            this.single = selection.length != 1;
            this.multiple = !selection.length;
        },

        /** 修改按钮操作 */
        handleUpdate(row) {
            this.open = true;
            this.form = row
        },
        handleDetail(row) {
            console.log(row);
            this.detailOPen = true;
            let obj = {
                advReportId: row.advReportId,
                ipAddress: this.$VUE_APP_IMG_API
            }
            advReportInfo(obj).then((res) => {
                this.rowDetail = res.data;
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const configId = row.advReportId || this.ids;
            this.$modal
                .confirm('是否确认删除此条数据？')
                .then(function () {
                    return advReportDel(configId);
                })
                .then(() => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                })
                .catch(() => { });
        },
        cancel() {
            this.open = false;
            this.detailOPen = false;
        },
        handleAdd() {
            // this.$router.push("./textsFileAdd");
            this.open = true;
            this.form = {}
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate((valid) => {
                if (valid) {
                    if (this.form.advReportId != undefined) {
                        this.form.createTime = ''
                        advReportEdit(this.form).then((response) => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        // this.form.busType = 2;
                        advReportAdd(this.form).then((response) => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 查询列表 */
        getList() {
            this.loading = true;
            noticeList(this.queryParams).then((response) => {
                this.dataList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        /** 查询部门下拉树结构 */
        getDeptTree() {
            deptTreeSelect().then((response) => {
                this.deptOptions = response.data;
            });
        },

        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
    },
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
    img {
        width: 100%;
    }
}
</style>
  